import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '栏目名称',
    dataIndex: 'deptName',
    align: 'left',
  },
  {
    title: '栏目Tag',
    dataIndex: 'tag',
    width: 120,
  },
  {
    title: '栏目缩写',
    dataIndex: 'pinyin',
    helpMessage:'栏目全拼首字母缩写',
    width: 120,
  },
  {
    title: '栏目首字母',
    dataIndex: 'py',
    helpMessage:'栏目首字母缩写',
    width: 110,
  },
  {
    title: '是否允许投稿',
    dataIndex: 'status',
    width: 120,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 0;
      const color = enable ? 'green' : 'red';
      const text = enable ? '允许' : '不允许';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '链接地址',
    dataIndex: 'url',
    width: 240,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    sorter: true,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 0;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '排序',
    dataIndex: 'orderNo',
    width: 100,
    sorter: true,
  },
  {
    title: '创建时间',
    dataIndex: 'id',
    width: 180,
    sorter: true,
    fixed: 'right',
    customRender: ({record})=>{
      return record.createTime;
    }
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '栏目名称',
    component: 'Input',
    colProps: { xs: 24, xl: 12, lg: 8, xxl: 6 },
  },
  {
    field: 'tag',
    label: '栏目Tag',
    component: 'Input',
    colProps: { xs: 24, xl: 12, lg: 8, xxl: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'parentDept',
    label: '上级栏目',
    component: 'TreeSelect',
    ifShow({ values }) {
      const { deptName, parentDept } = values;
      // Hide without a parentDept when editing
      return parentDept || (!deptName && !parentDept);
    },
    componentProps: {
      fieldNames: {
        label: 'deptName',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    required: false,
  },
  {
    field: 'deptName',
    label: '栏目名称',
    component: 'Input',
    required: true,
  },
  {
    label: '拼音缩写',
    field: 'pinyin',
    helpMessage:'栏目全拼首字母缩写',
    required: true,
    component: 'Input'
  },
  {
    label: '首字母',
    field: 'py',
    helpMessage:'栏目首字母缩写',
    required: true,
    component: 'Input'
  },
  {
    field: 'url',
    label: '链接地址',
    component: 'Input',
    required: true,
  },
  {
    field: 'orderNo',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'status1',
    label: '是否允许投稿',
    component: 'RadioButtonGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '允许', value: '1' },
        { label: '不允许', value: '0' },
      ],
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '停用', value: '0' },
      ],
    },
    required: true,
  },
  {
    field: 'meta_title',
    label: 'MetaTitle',
    component: 'InputTextArea',
  },
  {
    field: 'meta_keyword',
    label: 'MetaKeyword',
    component: 'InputTextArea',
  },
  {
    field: 'meta_description',
    label: 'MetaDescription',
    component: 'InputTextArea',
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
